﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pinger
{
	internal class Hosts
	{
		internal static List<Host> List()
		{
			return DB.ExecuteQuery<Host>("select ID, Name, Description from Hosts order by coalesce(Description,Name) collate nocase, Name collate nocase");
		}

		internal static bool Update(Host host)
		{
			var affected = DB.ExecuteNonQuery("update Hosts set Name=@Name, Description=@Description where ID=@ID", new DataDictionary { { "Name", host.Name }, { "Description", host.Description }, { "ID", host.ID } });
			return affected == 1;
		}

		internal static bool Insert(Host host)
		{
			var affected = DB.ExecuteNonQuery("insert into Hosts (Name, Description) values (@Name, @Description)", new DataDictionary { { "Name", host.Name }, { "Description", host.Description } });
			return affected == 1;
		}

		internal static bool Delete(Host host)
		{
			var affected = DB.ExecuteNonQuery("delete from Hosts where ID=@ID", new DataDictionary { { "ID", host.ID } });
			return affected == 1;
		}

	}
}
